/**
 * 
 */
package demo;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import bean.Course;
import bean.Student;
import dao.StudentDao;
/**
 * 1.如果操作的时候不给集合名，那么集合名默认为对象的首字母小写,如:Student----> student
 * 
 * @author liuxing
 *
 */
public class SpringMainDriver {
	
	private StudentDao dao = null;
	
	@Before
	public void init(){
		ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
		dao = (StudentDao) ac.getBean("studentDao");
		
	}

	@Test
	public void addStudent(){
		Student s = new Student();
		s.setUser_id(5d);
		s.setUser_name("lxxx");
		List<Course> slist = new ArrayList<>();
		slist.add(new Course(1, "CoreJava", 90d));
		slist.add(new Course(2, "CoreJava", 93d));
		s.setCourList(slist);
		dao.insert(s);
	}

	@Test
	public void findAll(){
		List<Student> stuList = dao.getStudentList();
		System.out.println(stuList);
	}
	
	@Test
	public void oneCondition(){
		List<Student> stuList = dao.getStudentList("liuxing");
		System.out.println(stuList);
	}
	
	@Test
	public void nCondition(){
		List<Student> studentList = dao.getStudentList(2d, "liuxing");
		System.out.println(studentList);
	}
	
	@Test
	public void mohu(){
		List<Student> list = dao.getStudentListWithSingleFuzzy("liuxing");
		System.out.println(list);
	}

}
